package cn.zhf.shop.service.impl;

import cn.zhf.shop.entity.Message;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.zhf.shop.mapper.ShoppingMapper;
import cn.zhf.shop.entity.Shopping;
import cn.zhf.shop.service.ShoppingService;

import java.util.List;

@Service
public class ShoppingServiceImpl implements ShoppingService {

    @Resource
    private ShoppingMapper shoppingMapper;

    @Override
    public Message<?> deleteByPrimaryKey(Integer shoppingId) {

        return shoppingMapper.deleteByPrimaryKey(shoppingId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> insert(Shopping record) {
        return shoppingMapper.insert(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> insertSelective(Shopping record) {
        return shoppingMapper.insertSelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<Shopping> selectByPrimaryKey(Integer shoppingId) {
        return Message.success(null).add(shoppingMapper.selectByPrimaryKey(shoppingId));
    }

    @Override
    public Message<?> updateByPrimaryKeySelective(Shopping record) {
        return shoppingMapper.updateByPrimaryKeySelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> updateByPrimaryKey(Shopping record) {
        return shoppingMapper.updateByPrimaryKey(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Integer countByUserId(String userId) {
        return shoppingMapper.countByUserId(userId);
    }

    @Override
    public Message<List<Shopping>> selectAllByUserId(String userId) {
        return Message.success(null).add(shoppingMapper.selectAllByUserId(userId));
    }

    @Override
    public Message<?> updateLessonNumByShoppingId(Integer shoppingId, Integer num) {
        return shoppingMapper.updateLessonNumByShoppingId(num, shoppingId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Shopping selectByUserIdAndLessonId(String userId, Integer lessonId) {
        return shoppingMapper.selectByUserIdAndLessonId(userId, lessonId);
    }

    @Override
    public Shopping selectByPrimaryKey2(Integer shoppingId) {
        return shoppingMapper.selectByPrimaryKey(shoppingId);
    }

}

